package com.xiaoyung.easyis.app.demo.config;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.xiaoyung.easyisapisdk.feign.api.util.CallMethodUtil;

//考虑不部署在云函数中部署docker中,使用此接口通信
@RestController
@RequestMapping(value="/rpc")
public class HttpRpcController {

	//class method args 全都放param里
	@PostMapping(value="/call")
	@ResponseBody
	public Object call(@RequestBody JSONObject param) {
		Object ret = CallMethodUtil.callClassInstanceMethod(param);
		return ret;
	}
	
	//class method放url里  args(array类型)通过body传入
	@PostMapping(value="/{class}/{method}")
	@ResponseBody
	public Object call(@PathVariable("class") String service,@PathVariable("method") String method,@RequestBody JSONArray param) {
		JSONObject p = new JSONObject();
		p.put("class", service);
		p.put("method", method);
		p.put("args", param);
		Object ret = CallMethodUtil.callClassInstanceMethod(p);
		return ret;
	}
	
}
